﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace CECB
{
    /// <summary>
    /// Interaction logic for Member_Window.xaml
    /// </summary>
    public partial class Member_Window : Window
    {
        public Member_Window()
        {
            InitializeComponent();
            
        }

        private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
        {
            Regex regex = new Regex("[^0-9]+");
            e.Handled = regex.IsMatch(e.Text);

            if (textBox_ContactNo.Text.Length == 10)
                e.Handled = true;
        }
 

        private void Email_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
           
        }

         

        private void button_Save_Cancel_Click(object sender, RoutedEventArgs e)
        {

            Dss.Methods.Member mem = new Dss.Methods.Member();
            MessageBox.Show(mem.getNewMemberReference());
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            Int32 ContactNo = 0;


            if (textBox_FirstName.Text.Length == 0)
            {
                MessageBox.Show("Enter First Name");
            }
            else if (textBox_LastName.Text.Length == 0)
            {
                MessageBox.Show("Enter Last Name");
            }
            else if (textBox_Nic.Text.Length == 0)
            {
                MessageBox.Show("Enter NIC");
            }
            else if (textBox_Designation.Text.Length == 0)
            {
                MessageBox.Show("Enter Designation");
            }
            else if (textBox_Address.Text.Length == 0)
            {
                MessageBox.Show("Enter Address");
            }
            else if (textBox_ContactNo.Text.Length == 0)
            {
                MessageBox.Show("Enter Contact Number");
            }
            else if (textBox_Email.Text.Length == 0)
            {
                MessageBox.Show("Enter Email");
            }
            else
            {
                try
                {
                    ContactNo = Int32.Parse(textBox_ContactNo.Text.Trim());

                    Dss.Methods.Member mem = new Dss.Methods.Member();

                    if (mem.InsertMember(textBox_FirstName.Text.Trim(),
                                            textBox_LastName.Text.Trim(),
                                            textBox_Designation.Text.Trim(),
                                            textBox_Nic.Text.Trim(),
                                            ContactNo,
                                            textBox_Email.Text.Trim()))
                    {
                        MessageBox.Show("Member Inserted Successfully");
                        clear();
                    }

                }
                catch (OverflowException)
                {
                    MessageBox.Show("Incorect Contact No!");
                }


            }
               
        }

        public void clear() {
            textBox_FirstName.Clear();
            textBox_LastName.Clear();
            textBox_Nic.Clear();
            textBox_Email.Clear();
            textBox_Designation.Clear();
            textBox_ContactNo.Clear();
            textBox_Address.Clear();
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
